/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */

#ifndef __LIB2D_NODE_NODEBASE_H__
#define __LIB2D_NODE_NODEBASE_H__

#include <animate/Node.h>
#include <lib2d/math.h>
#include <Atom.h>
#include <xml/Object.h>

namespace liba
{
namespace lib2d
{
namespace node
{

class NodeBase :
	public animate::Node,
	public xml::ObjectANSI
{
public:
	//Attributes
	static const Atom scale_name;
	static const Atom rotation_name;
	static const Atom position_name;

	explicit NodeBase( const Atom & name );
	virtual ~NodeBase()
	{}

	using animate::Node::change_attribute;
	using animate::Node::get_attribute;

	virtual bool change_attribute( const Atom & name, const math::Vector<double,2> & value );
	virtual bool get_attribute( const Atom & name, math::Vector<double,2> * value )const;
	virtual bool change_attribute( const Atom & name, double value );
	virtual bool get_attribute( const Atom & name, double * value )const;

//	const Matrix & get_matrix()const;

	const Vector & get_position()const;
	void change_position( const Vector & pos );

	double get_rotation()const;
	void change_rotation( double rot );

	const Vector & get_scale()const;
	void change_scale( const Vector & scale );

/*	const Matrix & get_total_matrix()const
	{
		return total_matrix;
	}
	*/
protected:
	virtual bool on_attribute( xml::Provider * prov, const String & name, const String & value );

	mutable bool dirty_matrix;
//	mutable Matrix matrix;
//	Matrix total_matrix;

	Vector position;
	double rotation;
	Vector scale;

//	void set_matrix( const Matrix & mat );
};

inline const Vector & NodeBase::get_position()const
{
	return position;
}

inline void NodeBase::change_position( const Vector & pos )
{
	position = pos;
	dirty_matrix = true;
}

inline double NodeBase::get_rotation()const
{
	return rotation;
}

inline void NodeBase::change_rotation( double rot )
{
	rotation = rot;
	dirty_matrix = true;
}

inline const Vector & NodeBase::get_scale()const
{
	return scale;
}

inline void NodeBase::change_scale( const Vector & scale )
{
	this->scale = scale;
	dirty_matrix = true;
}

} // namespace node
} // namespace lib2d
} // namespace liba
using namespace liba;

#endif //__LIB2D_NODE_NODEBASE_H__

